/*
  1.该文件是用于创建为Count组件服务的reducer,reducer本质就是一个函数
  2.reducer函数接收两个参数,分别为:之前的状态(preState)，动作对象(action)
*/
import { INCREMENT, DECREMENT } from './constant'

//初始化状态
const initState = 0
export default function countReducer(preState = initState, action) {
  // console.log(preState, action) //0  {"type": "@@redux/INITv.k.o.k.3.j"}
  

  //从action对象中解构出type和data
  const { type, data } = action

  switch (type) {
    case INCREMENT:
      return preState + data
    case DECREMENT:
      return preState - data
    default:
      return preState
  }
}
